#{extends '/template/main.html' /}
<!-- Removing search and results count filter -->
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">全部产品</h3>
        <div class="panel-options">
            <a href="/BS0019/admin/product/add">
                <button class="btn btn-success btn-icon">
                    <i class="fa-plus-square-o"></i>
                    <span>添加产品</span>
                </button>
            </a>
        </div>
    </div>
    <div class="panel-body">
        <form method="get" id="searchForm" action="/BS0019/admin/product/index/${pageNumber}">
            <div style="margin-bottom: 20px;width:160px;float: left;">
                <input type="text" name="name" id="name" class="form-control" style="width:150px" placeholder="产品名称" value="${name}">
            </div>
            <div style="margin-bottom: 20px;width:160px;float: left; margin-right:10px;">
                <select class="form-control" name="productType" data-validate="required" id="productType">
                    <option>请选择类别</option>
                    #{list items:productTypeList,as :'productType2'}
                        #{if productType2.id == productType}
                            <option value="${productType2?.id}" selected="true">${productType2?.name} </option>
                        #{/if}
                    #{else }
                        <option value="${productType2?.id}" >${productType2?.name} </option>
                    #{/else}

                    #{/list}
                </select>
            </div>
        </form>
        <button class="btn btn-turquoise" id="searchBtn">开始检索</button>
        <table class="table table-bordered table-striped" id="example-2">
            <thead>
            <tr>
                <th>名称</th>
                <th>所属类别</th>
                <th>主图</th>
                <th>库存</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody class="middle-align">
            #{paginate.list items:resultPage , as :'product'}
            <tr>
                <td>${product?.name}</td>
                <td>${product?.productType?.name}</td>
                <td><img src="${product?.mainImage}" style="width: 40px;"></td>
                <td>${product?.stock}</td>
                <td>${product?.status}</td>
                <td>
                    <a href="/BS0019/admin/product/modify/${product?.id}/${pageNumber}" class="btn btn-secondary btn-sm btn-icon icon-left">
                        编辑
                    </a>
                    <a href="#" onclick="deletedComfim(${product?.id});" class="btn btn-danger btn-sm btn-icon icon-left">
                        删除
                    </a>
                </td>
            </tr>
            #{/paginate.list}
            </tbody>
        </table>
        <div id="layerPage" class="col-xs-12"></div>
    </div>
</div>

<!-- Imported styles on this page -->
<link rel="stylesheet" href="/public/js/datatables/dataTables.bootstrap.css">

<script src="/public/js/datatables/js/jquery.dataTables.min.js"></script>


<!-- Imported scripts on this page -->
<script src="/public/js/datatables/dataTables.bootstrap.js"></script>
<script src="/public/js/datatables/yadcf/jquery.dataTables.yadcf.js"></script>
<script src="/public/js/datatables/tabletools/dataTables.tableTools.min.js"></script>

<script type="text/javascript" src="/public/laypage/laypage.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        // 提示
        var msg = '${flash.get("msg")}';
        if(msg) {
            saveSuccess(msg);
        }
        // 分页
        laypage({
            cont: $('#layerPage'), //容器。值支持id名、原生dom对象，jquery对象,
            pages: '${resultPage?.pageCount}', //总页数
            skin: 'yahei',
            curr:'${pageNumber}',
            jump: function(e, first){ //触发分页后的回调
                if(!first){ //一定要加此判断，否则初始时会无限刷新
                    $('#pageNumber').val(e.curr);
                    $("#searchForm").attr("action", "/BS0019/admin/product/index/"+e.curr);
                    $('#searchForm').submit();
                }
            }
        });
        $(document).on("click", "#searchBtn", function(){
            $("#searchForm").attr("action", "/BS0019/admin/product/index/1");
            $('#searchForm').submit();
        })

    });
    //点击确认删除 之后执行的方法
    function sureDeleted() {
        //获取删除的id
        var id = $('#deleteId').val();
        document.location.href='/BS0019/admin/product/delete/'+id+'/${pageNumber}';
    }

</script>


